<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        //1.移除数组 arr[1, 2, 3, 4, 2] 中的2。不要直接修改数组 arr，结果返回新的数组
        /*
        let arr = [1, 2, 3, 4, 2];
        let newArr = [];
        for (let i = 0; i < arr.length; i++) {
            if (arr[i] != 2) {
                newArr.push(arr[i]);
            }
        }
        console.log(newArr);
        */

        //2.定义一个函数,能在数组 arr[1, 2, 3, 4, 2] 的 "2"后面添加元素 "Melon"。不要直接修改数组 arr，结果返回新的数组
        /*
        补:
        DONE
        let arr = [1, 2, 3, 4, 2];
        function fn(arr, num, str) {
            for (let i = 0; i < arr.length; i++) {
                if (arr[i] == num) {
                    newArr.push(arr[i], str);
                }
                else {
                    newArr.push(arr[i]);
                }
            }
            return newArr;
        }
        console.log(arr, 2, "Melon");
        */


        //3.统计数组 arr[1, 2, 3, 4, 2] 中2出现的次数
        /*
        补:
            let arr = [1, 2, 3, 4, 2];
            function re(arr, el) {
            let count = 0;
            for (let i = 0; i < arr.length; i++) {
                if (arr[i] == el) {
                    count++;
                }
            }
            return count;
        }
        console.log(re(arr, 2));
        */

        //4.在arr里面输出年龄小于17的对象
        // var arr = [{
        //         name: "111",
        //         sex: "boy",
        //         age: 18
        //     },
        //     {
        //         name: "222",
        //         sex: "girl",
        //         age: 17
        //     },
        //     {
        //         name: "333",
        //         sex: "boy",
        //         age: 16
        //     },
        //     {
        //         name: "444",
        //         sex: "girl",
        //         age: 15
        //     },
        //     {
        //         name: "555",
        //         sex: "boy",
        //         age: 20
        //     }
        // ]
        /*
        待补完整
        TODO
        for (let i = 0; i < arr.length; i++) {
            if (arr[i].age < 17) {
                console.log(arr[i]);
            }
        }
        */

        //5.分析结果
        /*
        var b = "boy";
        console.log(b);
        function fighting() {
            console.log(a);
            console.log(c);
            if (a === "apple") {
                a = "Alice";
            } else {
                a = "Ada";
            }
            console.log(a);
            var a = "Andy";
            middle();
            function middle() {
                console.log(c++);
                var c = 100;
                console.log(++c);
                small();
                function small() {
                    console.log(a);
                }
            }
            var c = (a = 88);
            function bottom() {
                b = "baby";
                console.log(b);
            }
            bottom();
        }
        fighting();
        console.log(b); 
        */

        /*
        补
        TODO
        function fighting() {
            function middle() {
                function small() {
                console.log(a); //andy
                }
                var c;
                console.log(c++); //NaN
                c = 100;
                console.log(++c); //101
                small();
            }
            function bottom() {
                b = "baby";
                console.log(b); //baby
            }
            var a;
            var c;
            console.log(a); //undefined
            console.log(c); //undefined
            if (a === "apple") {
                a = "Alice";
            } else {
                a = "Ada";
            }
            console.log(a); //Ada
            a = "Andy";
            middle();
            c = a = 88;
            bottom();
        }
        var b = "boy";
        console.log(b); //boy
        fighting();
        console.log(b); //baby
        */
    </script>
</body>

</html>